"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _react = require("react");
/**
 * 添加复选框功能
 * @param table
 */
var useRowSelection = function useRowSelection(table, enableRowSelection) {
  var _useState = (0, _react.useState)([]),
    _useState2 = (0, _slicedToArray2.default)(_useState, 2),
    selectedRowKeys = _useState2[0],
    setSelectedRowKeys = _useState2[1];
  if (!enableRowSelection) return;
  var onSelectionChange = function onSelectionChange(selectedRowKeys) {
    setSelectedRowKeys(selectedRowKeys);
  };
  table.props.rowSelection = {
    selectedRowKeys: selectedRowKeys,
    // @ts-ignore
    onChange: onSelectionChange
  };
  table.getSelectedRowKeys = function () {
    return selectedRowKeys;
  };
  table.clearSelectedRowKeys = function () {
    setSelectedRowKeys([]);
  };
  var originSearch = table.search;
  table.search = function () {
    table.clearSelectedRowKeys && table.clearSelectedRowKeys();
    return originSearch.apply(void 0, arguments);
  };
  var originResearch = table.research;
  table.research = function () {
    table.clearSelectedRowKeys && table.clearSelectedRowKeys();
    return originResearch.apply(void 0, arguments);
  };
  var originReset = table.reset;
  table.reset = function () {
    table.clearSelectedRowKeys && table.clearSelectedRowKeys();
    return originReset();
  };
};
var _default = useRowSelection;
exports.default = _default;